package com;

/**
 * 例子说明 线程的构造方法由main线程调用
 * 而run方法由 子线程调用
 */
public class Demo02 {
    public static void main(String[] args) {
        TestThread testThread = new TestThread();
        testThread.start();
    }
}

class TestThread extends Thread {

    public TestThread() {
        System.out.println("begin");
        System.out.println("Thread.currentThread().getName(): " + Thread.currentThread().getName());
        System.out.println("this.getName(): " + this.getName());
        System.out.println("end");
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("begin");
        System.out.println("Thread.currentThread().getName(): " + Thread.currentThread().getName());
        System.out.println("this.getName(): " + this.getName());
        System.out.println("end");
    }
}
